﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Training9
{
    public partial class frmCourseAdd : Form
    {
        public frmCourseAdd()
        {
            InitializeComponent();
        }

        private void frmCourseAdd_Load(object sender, EventArgs e)
        {
            SqlOperate obj = new SqlOperate();
            string strSql = "select courseTypeName from T_CourseType";
            SqlDataReader odr = obj.GetDR(strSql);
            while (odr.Read())
            {
                comboBox1.Items.Add(odr.GetValue(0).ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlOperate obj = new SqlOperate();
            string strSql = "insert into T_Course(courseID,courseName,courseType,notes) values('" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "','" + textBox3.Text + "')";
            if (obj.RunSql(strSql) > 0)
            {
                MessageBox.Show("添加记录成功！", "信息提示", MessageBoxButtons.OK);
                DataGridViewRow row = new DataGridViewRow();
                int index = dataGridView1.Rows.Add(row);
                dataGridView1.Rows[index].Cells[0].Value = textBox1.Text;
                dataGridView1.Rows[index].Cells[1].Value = textBox2.Text;
                dataGridView1.Rows[index].Cells[2].Value = comboBox1.Text;
                dataGridView1.Rows[index].Cells[3].Value = textBox3.Text;
            }
            else
            {
                MessageBox.Show("添加记录失败！", "信息提示", MessageBoxButtons.OK);
            }
        }
    }
}
